/*     */ package com.cr.web.controller.system;
/*     */ 
/*     */ import com.cr.common.annotation.Log;
/*     */ import com.cr.common.core.controller.BaseController;
/*     */ import com.cr.common.core.domain.AjaxResult;
/*     */ import com.cr.common.core.domain.entity.SysRole;
/*     */ import com.cr.common.core.domain.entity.SysUser;
/*     */ import com.cr.common.core.page.TableDataInfo;
/*     */ import com.cr.common.enums.BusinessType;
/*     */ import com.cr.common.utils.poi.ExcelUtil;
/*     */ import com.cr.framework.shiro.util.AuthorizationUtils;
/*     */ import com.cr.system.domain.SysUserRole;
/*     */ import com.cr.system.service.ISysRoleService;
/*     */ import com.cr.system.service.ISysUserService;
/*     */ import java.util.List;
/*     */ import org.apache.shiro.authz.annotation.RequiresPermissions;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.ModelMap;
/*     */ import org.springframework.validation.annotation.Validated;
/*     */ import org.springframework.web.bind.annotation.GetMapping;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.PostMapping;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/system/role"})
/*     */ public class SysRoleController extends BaseController {
/*  37 */   private String prefix = "system/role";
/*     */   
/*     */   @Autowired
/*     */   private ISysRoleService roleService;
/*     */   
/*     */   @Autowired
/*     */   private ISysUserService userService;
/*     */   
/*     */   @RequiresPermissions({"system:role:view"})
/*     */   @GetMapping
/*     */   public String role() {
/*  49 */     return this.prefix + "/role";
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"system:role:list"})
/*     */   @PostMapping({"/list"})
/*     */   @ResponseBody
/*     */   public TableDataInfo list(SysRole role) {
/*  57 */     startPage();
/*  58 */     List<SysRole> list = this.roleService.selectRoleList(role);
/*  59 */     return getDataTable(list);
/*     */   }
/*     */   
/*     */   @Log(title = "角色管理", businessType = BusinessType.EXPORT)
/*     */   @RequiresPermissions({"system:role:export"})
/*     */   @PostMapping({"/export"})
/*     */   @ResponseBody
/*     */   public AjaxResult export(SysRole role) {
/*  68 */     List<SysRole> list = this.roleService.selectRoleList(role);
/*  69 */     ExcelUtil<SysRole> util = new ExcelUtil(SysRole.class);
/*  70 */     return util.exportExcel(list, "角色数据");
/*     */   }
/*     */   
/*     */   @GetMapping({"/add"})
/*     */   public String add() {
/*  79 */     return this.prefix + "/add";
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"system:role:add"})
/*     */   @Log(title = "角色管理", businessType = BusinessType.INSERT)
/*     */   @PostMapping({"/add"})
/*     */   @ResponseBody
/*     */   public AjaxResult addSave(@Validated SysRole role) {
/*  91 */     if ("1".equals(this.roleService.checkRoleNameUnique(role)))
/*  93 */       return error("新增角色'" + role.getRoleName() + "'失败，角色名称已存在"); 
/*  95 */     if ("1".equals(this.roleService.checkRoleKeyUnique(role)))
/*  97 */       return error("新增角色'" + role.getRoleName() + "'失败，角色权限已存在"); 
/*  99 */     role.setCreateBy(getLoginName());
/* 100 */     AuthorizationUtils.clearAllCachedAuthorizationInfo();
/* 101 */     return toAjax(this.roleService.insertRole(role));
/*     */   }
/*     */   
/*     */   @GetMapping({"/edit/{roleId}"})
/*     */   public String edit(@PathVariable("roleId") Long roleId, ModelMap mmap) {
/* 111 */     this.roleService.checkRoleDataScope(roleId);
/* 112 */     mmap.put("role", this.roleService.selectRoleById(roleId));
/* 113 */     return this.prefix + "/edit";
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"system:role:edit"})
/*     */   @Log(title = "角色管理", businessType = BusinessType.UPDATE)
/*     */   @PostMapping({"/edit"})
/*     */   @ResponseBody
/*     */   public AjaxResult editSave(@Validated SysRole role) {
/* 125 */     this.roleService.checkRoleAllowed(role);
/* 126 */     if ("1".equals(this.roleService.checkRoleNameUnique(role)))
/* 128 */       return error("修改角色'" + role.getRoleName() + "'失败，角色名称已存在"); 
/* 130 */     if ("1".equals(this.roleService.checkRoleKeyUnique(role)))
/* 132 */       return error("修改角色'" + role.getRoleName() + "'失败，角色权限已存在"); 
/* 134 */     role.setUpdateBy(getLoginName());
/* 135 */     AuthorizationUtils.clearAllCachedAuthorizationInfo();
/* 136 */     return toAjax(this.roleService.updateRole(role));
/*     */   }
/*     */   
/*     */   @GetMapping({"/authDataScope/{roleId}"})
/*     */   public String authDataScope(@PathVariable("roleId") Long roleId, ModelMap mmap) {
/* 145 */     mmap.put("role", this.roleService.selectRoleById(roleId));
/* 146 */     return this.prefix + "/dataScope";
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"system:role:edit"})
/*     */   @Log(title = "角色管理", businessType = BusinessType.UPDATE)
/*     */   @PostMapping({"/authDataScope"})
/*     */   @ResponseBody
/*     */   public AjaxResult authDataScopeSave(SysRole role) {
/* 158 */     this.roleService.checkRoleAllowed(role);
/* 159 */     role.setUpdateBy(getLoginName());
/* 160 */     if (this.roleService.authDataScope(role) > 0) {
/* 162 */       setSysUser(this.userService.selectUserById(getUserId()));
/* 163 */       return success();
/*     */     } 
/* 165 */     return error();
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"system:role:remove"})
/*     */   @Log(title = "角色管理", businessType = BusinessType.DELETE)
/*     */   @PostMapping({"/remove"})
/*     */   @ResponseBody
/*     */   public AjaxResult remove(String ids) {
/* 174 */     return toAjax(this.roleService.deleteRoleByIds(ids));
/*     */   }
/*     */   
/*     */   @PostMapping({"/checkRoleNameUnique"})
/*     */   @ResponseBody
/*     */   public String checkRoleNameUnique(SysRole role) {
/* 184 */     return this.roleService.checkRoleNameUnique(role);
/*     */   }
/*     */   
/*     */   @PostMapping({"/checkRoleKeyUnique"})
/*     */   @ResponseBody
/*     */   public String checkRoleKeyUnique(SysRole role) {
/* 194 */     return this.roleService.checkRoleKeyUnique(role);
/*     */   }
/*     */   
/*     */   @GetMapping({"/selectMenuTree"})
/*     */   public String selectMenuTree() {
/* 203 */     return this.prefix + "/tree";
/*     */   }
/*     */   
/*     */   @Log(title = "角色管理", businessType = BusinessType.UPDATE)
/*     */   @RequiresPermissions({"system:role:edit"})
/*     */   @PostMapping({"/changeStatus"})
/*     */   @ResponseBody
/*     */   public AjaxResult changeStatus(SysRole role) {
/* 215 */     this.roleService.checkRoleAllowed(role);
/* 216 */     return toAjax(this.roleService.changeStatus(role));
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"system:role:edit"})
/*     */   @GetMapping({"/authUser/{roleId}"})
/*     */   public String authUser(@PathVariable("roleId") Long roleId, ModelMap mmap) {
/* 226 */     mmap.put("role", this.roleService.selectRoleById(roleId));
/* 227 */     return this.prefix + "/authUser";
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"system:role:list"})
/*     */   @PostMapping({"/authUser/allocatedList"})
/*     */   @ResponseBody
/*     */   public TableDataInfo allocatedList(SysUser user) {
/* 238 */     startPage();
/* 239 */     List<SysUser> list = this.userService.selectAllocatedList(user);
/* 240 */     return getDataTable(list);
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"system:role:edit"})
/*     */   @Log(title = "角色管理", businessType = BusinessType.GRANT)
/*     */   @PostMapping({"/authUser/cancel"})
/*     */   @ResponseBody
/*     */   public AjaxResult cancelAuthUser(SysUserRole userRole) {
/* 252 */     return toAjax(this.roleService.deleteAuthUser(userRole));
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"system:role:edit"})
/*     */   @Log(title = "角色管理", businessType = BusinessType.GRANT)
/*     */   @PostMapping({"/authUser/cancelAll"})
/*     */   @ResponseBody
/*     */   public AjaxResult cancelAuthUserAll(Long roleId, String userIds) {
/* 264 */     return toAjax(this.roleService.deleteAuthUsers(roleId, userIds));
/*     */   }
/*     */   
/*     */   @GetMapping({"/authUser/selectUser/{roleId}"})
/*     */   public String selectUser(@PathVariable("roleId") Long roleId, ModelMap mmap) {
/* 273 */     mmap.put("role", this.roleService.selectRoleById(roleId));
/* 274 */     return this.prefix + "/selectUser";
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"system:role:list"})
/*     */   @PostMapping({"/authUser/unallocatedList"})
/*     */   @ResponseBody
/*     */   public TableDataInfo unallocatedList(SysUser user) {
/* 285 */     startPage();
/* 286 */     List<SysUser> list = this.userService.selectUnallocatedList(user);
/* 287 */     return getDataTable(list);
/*     */   }
/*     */   
/*     */   @RequiresPermissions({"system:role:edit"})
/*     */   @Log(title = "角色管理", businessType = BusinessType.GRANT)
/*     */   @PostMapping({"/authUser/selectAll"})
/*     */   @ResponseBody
/*     */   public AjaxResult selectAuthUserAll(Long roleId, String userIds) {
/* 299 */     return toAjax(this.roleService.insertAuthUsers(roleId, userIds));
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\classes\com.zip!\com\cr\web\controller\system\SysRoleController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */